package gw_gs

import (
	"cade/src/game/app"
	"cade/src/game/msg"
	"time"
)

func GW_UserOnline(message msg.Message, ctx interface{}) {
	req := message.(*msg.GW_UserOnline)

	// logout old one first
	old := app.PlayerMgr.FindPlayer(req.UserId)
	if old != nil {
		old.Logout()
	}

	// we'll bring the new player online
	plr := app.NewPlayer(func(u *app.User) {
		u.Id = req.UserId
		u.Name = req.UserName
		u.LoginTs = time.Now()
		u.LoginIP = req.LoginIP
	})

	app.PlayerMgr.SetOnline(plr, req.Sid)
}
